package com.lhy.tool.generator.impl;

import com.lhy.tool.autoconfigation.GeneratorProperties;
import com.lhy.tool.generator.AbstractViewGenerator;
import com.lhy.tool.model.CrudBean;
import com.lhy.tool.util.StringUtil;
import lombok.Getter;
import lombok.Setter;

import java.io.File;

@Getter
@Setter
public class DefaultVueViewGenerator extends AbstractViewGenerator {

    @Override
    protected String templateName() {
        return "template.vue.ftl";
    }

//    private List<CrudColumn> queryColumns;

    private CrudBean crudBean;

    private String modelParamName;

    /**
     * {@inheritDoc}
     *
     * @Description: 写入属性 查询条件列
     */
    @Override
    protected void writeViewAttribute(CrudBean crudBean, GeneratorProperties generatorProperties) {
//        queryColumns = crudBean.getColumns().stream()
//                .filter(crudColumn -> crudColumn.getColumnAttributes().getQueryable())
//                .collect(Collectors.toList());
        this.crudBean = crudBean;
        this.modelParamName = StringUtil.firstToLowerCase(this.modelName);
    }

    @Override
    protected File getCodeFile() {
        String projectPath = this.getFileAttribute().getProjectPath();
        String viewPath = this.getControllerAttribute().getViewPath();
        String filePath = projectPath + viewPath + "/" + this.modelParamName + ".vue";
        return new File(filePath);
    }


}
